package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.IOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SupplyUserMapper;
import com.ruoyi.system.domain.SupplyUser;
import com.ruoyi.system.service.ISupplyUserService;

/**
 * 供应商用户Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@Service
public class SupplyUserServiceImpl implements ISupplyUserService 
{
    @Autowired
    private SupplyUserMapper supplyUserMapper;

    /**
     * 查询供应商用户
     * 
     * @param id 供应商用户主键
     * @return 供应商用户
     */
    @Override
    public SupplyUser selectSupplyUserById(Long id)
    {
        return supplyUserMapper.selectSupplyUserById(id);
    }

    /**
     * 查询供应商用户列表
     * 
     * @param supplyUser 供应商用户
     * @return 供应商用户
     */
    @Override
    public List<SupplyUser> selectSupplyUserList(SupplyUser supplyUser)
    {
        return supplyUserMapper.selectSupplyUserList(supplyUser);
    }

    /**
     * 新增供应商用户
     * 
     * @param supplyUser 供应商用户
     * @return 结果
     */
    @Override
    public AjaxResult insertSupplyUser(SupplyUser supplyUser)
    {
        //判断手机号是否已经存在
        SupplyUser selectUser = new SupplyUser();
        selectUser.setPhone(supplyUser.getPhone());
        List<SupplyUser> userList = supplyUserMapper.selectSupplyUserList(selectUser);
        if(userList!=null && userList.size()>0){
            return AjaxResult.error("手机号已经存在");
        }
        //加密密码
        supplyUser.setPwd(IOUtil.MD5(supplyUser.getPwd()));
        supplyUser.setType("2");
        int i = supplyUserMapper.insertSupplyUser(supplyUser);
        return AjaxResult.int2Ajax(i);
    }

    /**
     * 修改供应商用户
     * 
     * @param supplyUser 供应商用户
     * @return 结果
     */
    @Override
    public int updateSupplyUser(SupplyUser supplyUser)
    {
        return supplyUserMapper.updateSupplyUser(supplyUser);
    }

    /**
     * 批量删除供应商用户
     * 
     * @param ids 需要删除的供应商用户主键
     * @return 结果
     */
    @Override
    public int deleteSupplyUserByIds(Long[] ids)
    {
        return supplyUserMapper.deleteSupplyUserByIds(ids);
    }

    /**
     * 删除供应商用户信息
     * 
     * @param id 供应商用户主键
     * @return 结果
     */
    @Override
    public int deleteSupplyUserById(Long id)
    {
        return supplyUserMapper.deleteSupplyUserById(id);
    }
}
